<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Sends a query to the server</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="solrclient.ping.html">« SolrClient::ping</a></li>
      <li style="float: right;"><a href="solrclient.request.html">SolrClient::request »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.solrclient.html">SolrClient</a></li>
    <li>Sends a query to the server</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="solrclient.query" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">SolrClient::query</h1>
  <p class="verinfo">(PECL solr &gt;= 0.9.2)</p><p class="refpurpose"><span class="refname">SolrClient::query</span> &mdash; <span class="dc-title">Sends a query to the server</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-solrclient.query-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>SolrClient::query</strong></span>(<span class="methodparam"><span class="type"><a href="class.solrparams.html" class="type SolrParams">SolrParams</a></span> <code class="parameter">$query</code></span>): <span class="type"><a href="class.solrqueryresponse.html" class="type SolrQueryResponse">SolrQueryResponse</a></span></div>

  <p class="para rdfs-comment">
   Sends a query to the server.
  </p>

 </div>


 <div class="refsect1 parameters" id="refsect1-solrclient.query-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">query</code></dt>

     <dd>

      <p class="para">
       A <span class="type"><a href="class.solrparams.html" class="type SolrParams">SolrParams</a></span> object. It is recommended to use <span class="type"><a href="class.solrquery.html" class="type SolrQuery">SolrQuery</a></span> for advanced queries.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-solrclient.query-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns a <span class="type"><a href="class.solrqueryresponse.html" class="type SolrQueryResponse">SolrQueryResponse</a></span> object on success and throws an exception on failure.
  </p>
 </div>

 
 <div class="refsect1 errors" id="refsect1-solrclient.query-errors">
  <h3 class="title">错误／异常</h3>
  <p class="para">
   Throws <span class="classname"><a href="class.solrclientexception.html" class="classname">SolrClientException</a></span> if the client had failed, or there was a connection issue.
  </p>
  <p class="para">
    Throws <span class="classname"><a href="class.solrserverexception.html" class="classname">SolrServerException</a></span> if the Solr Server had failed to satisfy the query.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-solrclient.query-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-4643">
    <p><strong>示例 #1 <span class="methodname"><strong>SolrClient::query()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$options&nbsp;</span><span style="color: #007700">=&nbsp;array<br />(<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'hostname'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'localhost'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'login'&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'username'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'password'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'password'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'port'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'8983'</span><span style="color: #007700">,<br />);<br /><br /></span><span style="color: #0000BB">$client&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">SolrClient</span><span style="color: #007700">(</span><span style="color: #0000BB">$options</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$query&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">SolrQuery</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">$query</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setQuery</span><span style="color: #007700">(</span><span style="color: #DD0000">'lucene'</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$query</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setStart</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$query</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setRows</span><span style="color: #007700">(</span><span style="color: #0000BB">50</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$query</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">addField</span><span style="color: #007700">(</span><span style="color: #DD0000">'cat'</span><span style="color: #007700">)-&gt;</span><span style="color: #0000BB">addField</span><span style="color: #007700">(</span><span style="color: #DD0000">'features'</span><span style="color: #007700">)-&gt;</span><span style="color: #0000BB">addField</span><span style="color: #007700">(</span><span style="color: #DD0000">'id'</span><span style="color: #007700">)-&gt;</span><span style="color: #0000BB">addField</span><span style="color: #007700">(</span><span style="color: #DD0000">'timestamp'</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$query_response&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$client</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #0000BB">$query</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$response&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$query_response</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getResponse</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$response</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程的输出类似于：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
SolrObject Object
(
    [responseHeader] =&gt; SolrObject Object
        (
            [status] =&gt; 0
            [QTime] =&gt; 3
            [params] =&gt; SolrObject Object
                (
                    [fl] =&gt; cat,features,id,timestamp
                    [indent] =&gt; on
                    [start] =&gt; 0
                    [q] =&gt; lucene
                    [wt] =&gt; xml
                    [version] =&gt; 2.2
                    [rows] =&gt; 50
                )

        )

    [response] =&gt; SolrObject Object
        (
            [numFound] =&gt; 1
            [start] =&gt; 0
            [docs] =&gt; Array
                (
                    [0] =&gt; SolrObject Object
                        (
                            [id] =&gt; SOLR1000
                            [cat] =&gt; Array
                                (
                                    [0] =&gt; software
                                    [1] =&gt; search
                                )

                            [features] =&gt; Array
                                (
                                    [0] =&gt; Advanced Full-Text Search Capabilities using Lucene
                                    [1] =&gt; Optimized for High Volume Web Traffic
                                    [2] =&gt; Standards Based Open Interfaces - XML and HTTP
                                    [3] =&gt; Comprehensive HTML Administration Interfaces
                                    [4] =&gt; Scalability - Efficient Replication to other Solr Search Servers
                                    [5] =&gt; Flexible and Adaptable with XML configuration and Schema
                                    [6] =&gt; Good unicode support: héllo (hello with an accent over the e)
                                )

                        )

                )

        )

)
</pre></div>
    </div>
   </div>
  </p>
 </div>


</div></div></div></body></html>